package cn.xyz.commons.autoconfigure;

import com.github.jarod.qqwry.QQWry;
import lombok.extern.slf4j.Slf4j;
import sun.rmi.runtime.Log;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * 纯真ip
 */
@Slf4j
public class IpSearchCZ {

    private  static IpSearchCZ m_Interface = null;
    private QQWry m_qqwry = null;
    private IpSearchCZ(String szPath)
    {
        try {
            m_qqwry = new QQWry(Paths.get(szPath));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public  static  IpSearchCZ GetInterface(String szPath)
    {
        if(m_Interface ==null)
        {
            log.info("IpSearchCZ=="+szPath);
            m_Interface = new IpSearchCZ(szPath);
        }
        return m_Interface;
    }

    public String findIp(String szIpAdder)
    {
        String szMainInfo = m_qqwry.findIP(szIpAdder).getMainInfo();
        String szResult = szMainInfo;
         if(szMainInfo.indexOf("阿联酋")>-1)
         {
             szResult = "alq";
         }
         return szResult;
    }
    public  String findIpSubInfo(String szIpAdder)
    {
        return  m_qqwry.findIP(szIpAdder).getSubInfo();
    }
}
